#include "UM_Queue.h"

void RQ_Init(RQTypeDef *q,u16 **arr,u8 size)
{
	q->value = (u16*)arr;
	q->size = size;
    q->front = 0;
    q->rear = 0;
    q->updated = 0;
}

void RQ_Flush(RQTypeDef *q)
{
    q->front = 0;
    q->rear = 0;
    q->updated = 0;
}

RQRetTypeDef RQ_Pop(RQTypeDef *q,u16* value)
{
    if ( q->rear ==  q->front)
    {
        return RQ_EMPTY;
    }
    else
    {
        *value =  q->value[ q->front];
        q->value[ q->front] = 0;
        q->front = ( q->front+1)% q->size;
    }
    return RQ_OK;
}

RQRetTypeDef RQ_Push(RQTypeDef *q,u16 value)
{
	u8 next_rear = ( q->rear + 1) %  q->size;
	if (  next_rear ==  q->front )
	{
		return RQ_FULL;
	}
	else
	{
		q->value[ q->rear] = value;
		 q->rear = next_rear;
		 q->updated = 1;
	}
	return RQ_OK;
}

RQRetTypeDef RQ_Push1(RQTypeDef *q,u16 value)
{
	u8 next_rear = ( q->rear + 1) %  q->size;
	if (  next_rear ==  q->front )
	{
		return RQ_FULL;
	}
	else
	{
		 q->value[ q->rear] = value;
		 q->rear = next_rear;
		 q->updated = 1;
	}
	return RQ_OK;
}

RQRetTypeDef RQ_Push2(RQTypeDef *q,u16 value)
{
	u8 next_rear = ( q->rear + 1) %  q->size;
	if (  next_rear ==  q->front )
	{
		return RQ_FULL;
	}
	else
	{
		 q->value[ q->rear] = value;
		 q->rear = next_rear;
		 q->updated = 1;
	}
	return RQ_OK;
}

RQRetTypeDef RQ_Push3(RQTypeDef *q,u16 value)
{
	u8 next_rear = ( q->rear + 1) %  q->size;
	if (  next_rear ==  q->front )
	{
		return RQ_FULL;
	}
	else
	{
		 q->value[ q->rear] = value;
		 q->rear = next_rear;
		 q->updated = 1;
	}
	return RQ_OK;
}

RQRetTypeDef RQ_Push4(RQTypeDef *q,u16 value)
{
	u8 next_rear = ( q->rear + 1) %  q->size;
	if (  next_rear ==  q->front )
	{
		return RQ_FULL;
	}
	else
	{
		 q->value[ q->rear] = value;
		 q->rear = next_rear;
		 q->updated = 1;
	}
	return RQ_OK;
}

RQRetTypeDef RQ_Push5(RQTypeDef *q,u16 value)
{
	u8 next_rear = ( q->rear + 1) %  q->size;
	if (  next_rear ==  q->front )
	{
		return RQ_FULL;
	}
	else
	{
		 q->value[ q->rear] = value;
		 q->rear = next_rear;
		 q->updated = 1;
	}
	return RQ_OK;
}
